﻿@using System.Text
@using Coralcode.Adapter.StatVisit.Entity.Domains
@using Coralcode.Adapter.StatVisit.Entity.Enums
@using Coralcode.Utils.Basic
@using CoralNode.MvcClient.Helper
@using Coralcode.Utils.Basic.DateTimeUtil
@{
    ViewBag.Title = "流量分析-访问明细";
    ViewBag.PageModule = "flow";
    ViewBag.CurrentPageUrl = "/m/statistic/flowlog?groupby=" + ViewBag.groupby + "&ip=" + ViewBag.ip + "&";
}
@Html.IncludePage("CoralAdmin/statistic", "_Left")
<!--content-->
<div id="pbody">
    <div class="extra">
        @Html.IncludePage("CoralAdmin/statistic", "DateSelection")
        <div class="main-box mt_2 mb_2">
            <div class="tab-visit clearfix">
                <a href="/m/statistic/flow?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">访问趋势</a>
                <a href="/m/statistic/flowreport?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">统计报表</a>
                <a class="current" href="/m/statistic/flowlog?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselecte">访问明细</a>
            </div>
            <div class="clearfix">
                <div class="table_visit">
                    <div class="t pl_2 pr_2 clearfix">
                        <div class="filter_btn f_l">
                            <a @if (ViewBag.groupby != "s"){@String.Format("class=current") } href="/m/statistic/flowlog?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselect&ip=@ViewBag.ip&groupby=pv">按PV显示</a>
                            <a class="last @if (ViewBag.groupby == "s"){@String.Format("current") }" href="/m/statistic/flowlog?dateStart=@ViewBag.DateStart&dateEnd=@ViewBag.DateEnd&dateselect=@ViewBag.dateselect&ip=@ViewBag.ip&groupby=session">按访问显示</a>
                        </div>
                        <div class="f_r">
                            @using (Html.BeginForm("flowlog", "statistic", FormMethod.Get))
                            {
                                <input type="hidden" name="dateStart"value="@ViewBag.DateStart" />
                                <input type="hidden" name="dateEnd"value="@ViewBag.DateEnd" />
                                <input type="hidden" name="dateselect"value="@ViewBag.dateselect" />
                                <input type="hidden" name="groupby"value="@ViewBag.groupby" />
                                <label class="search f_l">
                                    <input class="text w_18" data-js='watermark' name="ip" data-msg="输入完整IP" value="@ViewBag.ip" ><input type="submit" value="" class="submit">
                                </label>
                                @*<div class="sch_high f_l ml_1"><a href="#">高级搜索及筛选</a></div>*@
                            }
                        </div>
                    </div>
                    <table class="table_visit_border" width="100%">
                        @if (ViewBag.groupby != "s") {
                            <thead>
                                <tr>
                                    <td width="20"></td>
                                    <td width="160">浏览时间</td>
                                    <td><label class="radio"><input checked type="radio" name="showselection" value="pagesource" />页面来源</label>
                                        <label class="radio"><input type="radio" name="showselection" value="searchengine" />仅搜索引擎</label>
                                    </td>
                                    <td>受访</td>
                                    <td align="center">IP</td>
                                    <td align="center">地区</td>
                                    <td width="5"></td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (StatVisitLogDomain log in ViewBag.PagerList.Items){
                                    <tr class="unfold_wrap @if (log.Equals(ViewBag.PagerList.LastItem)) {
                                                               @String.Format("last")
                                                           } @if (string.IsNullOrEmpty(log.RefSearchEngine)) {
                                                                 @String.Format("notsearchengine")
                                                             }">
                                        <td><div class="unfold"><i class="ico ico_up"></i></div></td>
                                        <td>@log.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                        <td>
                                            @if (string.IsNullOrEmpty(log.RefUrl)) {
                                                @String.Format("直接输入网址或书签")
                                                ;
                                            } else if (!string.IsNullOrEmpty(log.RefSearchEngine)) {
                                                <a class="color_green" title="@log.RefUrl" href="@log.RefUrl">@(log.RefSearchEngine)(@log.RefSearchKey)</a>
                                            } else {
                                                <a class="color_green" title="@log.RefUrl" href="@log.RefUrl">
                                                    @(log.RefUrl.Length > 70 ? log.RefUrl.Substring(0, 68) + "..." : log.RefUrl)
                                                </a>
                                            }
                                        </td>
                                        <td><a class="color_green" title="@log.CurrentUrl" href="@log.CurrentUrl">
                                                @((!string.IsNullOrEmpty(log.CurrentUrl) && log.CurrentUrl.Length > 70) ? log.CurrentUrl.Substring(0, 68) + "..." : log.CurrentUrl)    
                                            </a></td>
                                        <td align="center">@log.ClientIp</td>
                                        <td align="center">@log.City</td>
                                        <td></td>
                                    </tr>
                                    <tr class="unfold_cnt @if (log.Equals(ViewBag.PagerList.LastItem)){@String.Format("last")} ">
                                        <td colspan="7">
                                            <table width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td width="50"></td>
                                                        <td width="240">
                                                            新访客 @Html.ActionLink("只看该访客", "flowlog", "statistic", new {dateStart = ViewBag.DateStart, dateEnd = ViewBag.DateEnd, dateselect = ViewBag.dateselect, groupby = ViewBag.groupby, clientid = log.ClientId}, htmlAttributes: new {@class = "color_green"})
                                                        </td>
                                                        <td align="right" width="100"><span style="color: #777">首次来访时间：<br />上次浏览时间：</span></td>
                                                        <td width="230">@log.FirstVisitTime.ToString("yyyy-MM-dd HH:mm:ss")<br />@log.LastVisitTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                                        <td><span style="color: #777">首次来自：</span><br />@string.Format("本次为今日第{0}次来访", log.VisitCount)</td>
                                                        <td>@log.FirstVisitComesFrom</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <table width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td width="42"></td>
                                                        <td align="right" width="80"><span style="color: #777">网络接入商：<br />操作系统：</span></td>
                                                        <td width="168">@log.ClientIsp<br />@log.ClientOs</td>
                                                        <td align="right" width="100"><span style="color: #777">语言：<br />分辨率：</span></td>
                                                        <td width="230">@log.ClientLang<br />@log.ClientResolution</td>
                                                        <td align="right" width="60"><span style="color: #777">设备类型：<br />浏览器：</span></td>
                                                        <td>@log.ClientDevice<br />@log.ClientBrowser</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        } else {
                            <thead>
                                <tr>
                                    <td width="20"></td>
                                    <td width="160">浏览时间</td>
                                    <td><label class="radio"><input checked type="radio" name="showselection" value="pagesource" />页面来源</label>
                                        <label class="radio"><input type="radio" name="showselection" value="searchengine" />仅搜索引擎</label>
                                    </td>
                                    <td>最后受访页面</td>
                                    <td align="center">访问时长</td>
                                    <td align="center">深度</td>
                                    <td align="center">IP</td>
                                    <td align="center">地区</td>
                                    <td width="5"></td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (StatVisitLogDomain log in ViewBag.PagerList.Items){
                                    <tr class="unfold_wrap @if (log.Equals(ViewBag.PagerList.LastItem)) {
                                                               @String.Format("last")
                                                           } @if (string.IsNullOrEmpty(log.RefSearchEngine))
                                                             {
                                                                 @String.Format("notsearchengine")
                                                             }">
                                        <td><div class="unfold"><i class="ico ico_up"></i></div></td>
                                        <td>@log.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                        <td>
                                            @if (string.IsNullOrEmpty(log.RefUrl))
                                            {
                                                @String.Format("直接输入网址或书签")
                                            }
                                            else if (!string.IsNullOrEmpty(log.RefSearchEngine))
                                            {
                                                <a class="color_green" title="@log.RefUrl" href="@log.RefUrl">@(log.RefSearchEngine)(@log.RefSearchKey)</a>
                                            }
                                            else
                                            {
                                                <a class="color_green" title="@log.RefUrl" href="@log.RefUrl">
                                                    @(log.RefUrl.Length > 70 ? log.RefUrl.Substring(0, 68) + "..." : log.RefUrl)
                                                </a>
                                            }
                                        </td>
                                        <td><a class="color_green" title="@log.CurrentUrl" href="@log.CurrentUrl">
                                                @((!string.IsNullOrEmpty(log.CurrentUrl) && log.CurrentUrl.Length > 70) ? log.CurrentUrl.Substring(0, 68) + "..." : log.CurrentUrl)    
                                            </a></td>
                                        <td align="center">
                                            @DateTimeUtil.ToFriendlyFull(log.VisitLogs.First().CreateTime, log.VisitLogs.Last().CreateTime)
                                        </td>
                                        <td align="center">@log.VisitLogs.Count</td>
                                        <td align="center">@log.ClientIp</td>
                                        <td align="center">@log.City</td>
                                        <td></td>
                                    </tr>
                                    <tr class="unfold_cnt @if (log.Equals(ViewBag.PagerList.LastItem)){@String.Format("last")}">
                                        <td colspan="7">
                                            <table width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td width="50"></td>
                                                        <td width="240">
                                                            新访客 @Html.ActionLink("只看该访客", "flowlog", "statistic", new { dateStart = ViewBag.DateStart, dateEnd = ViewBag.DateEnd, dateselect = ViewBag.dateselect, groupby = ViewBag.groupby, clientid = log.ClientId }, htmlAttributes: new { @class = "color_green" })
                                                        </td>
                                                        <td align="right" width="100"><span style="color: #777">首次来访时间：<br />上次浏览时间：</span></td>
                                                        <td width="230">@log.FirstVisitTime.ToString("yyyy-MM-dd HH:mm:ss")<br />@log.LastVisitTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                                        <td><span style="color: #777">首次来自：</span><br />@string.Format("本次为今日第{0}次来访", log.VisitCount)</td>
                                                        <td>@log.FirstVisitComesFrom</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                            <table width="100%">
                                                <tbody>
                                                    <tr class="fix_width_title">
                                                        <td  align="center" width="60">访问轨迹</td>
                                                        <td width="160">打开时间</td>
                                                        <td>停留时长</td>
                                                        <td>页面地址</td>
                                                    </tr>
                                                    @for (int j = 0; j < log.VisitLogs.Count; j++)
                                                    {
                                                        var sublog = log.VisitLogs[j];
                                                        <tr>
                                                            <td align="center">@(j + 1)</td>
                                                            <td>@sublog.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                                                            <td>
                                                                @if (j < log.VisitLogs.Count - 1)
                                                                {
                                                                    @DateTimeUtil.ToFriendlyFull(log.VisitLogs[j].CreateTime, log.VisitLogs[j + 1].CreateTime)
                                                                }
                                                                else
                                                                {
                                                                    @("-")
                                                                }
                                                            </td>
                                                            <td class="blue12">
                                                                @sublog.CurrentUrl
                                                            </td>
                                                        </tr>
                                                    }
                                                </tbody>
                                            </table>
                                            <table width="100%">
                                                <tbody>
                                                    <tr>
                                                        <td width="42"></td>
                                                        <td align="right" width="80"><span style="color: #777">网络接入商：<br />操作系统：</span></td>
                                                        <td width="168">@log.ClientIsp<br />@log.ClientOs</td>
                                                        <td align="right" width="100"><span style="color: #777">语言：<br />分辨率：</span></td>
                                                        <td width="230">@log.ClientLang<br />@log.ClientResolution</td>
                                                        <td align="right" width="60"><span style="color: #777">设备类型：<br />浏览器：</span></td>
                                                        <td>@log.ClientDevice<br />@log.ClientBrowser</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        }
                    </table>
                    @Html.IncludePage("CoralAdmin/Shared", "Pager")
                </div>
            </div> 
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(":radio[name=showselection]").click(function() {
            if ($(this).is(":checked")) {
                if ($(this).val() == "searchengine") {
                    $(".notsearchengine").hide();
                } else {
                    $(".notsearchengine").show();
                }
                $(".unfold_cnt").hide();
                $(".unfold_wrap_curr").removeClass("unfold_wrap_curr");
            }
        });
    });
</script>